home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacScheme20 / Mathlib / legendre.scm < prev    next >
Encoding:
Text File  |  1989-04-27  |  913 b   |  28 lines  |  [TEXT/????]

  1. ;;; LEGENDRE.SCM -- the Legendre Polynomials returned as a stream or singly
  2.  
  3. ;;; The following procedure returns a stream whose nth term (0-based) is
  4. ;;; the coefficient-list representation of P[n]. We use the recurrence
  5. ;;; relation P[0](x) = 1, P[1](x) = x, and for n > 1:
  6. ;;;      P[n](x) = ((2n-1)/(2n))*x*P[n-1](x) - ((n-1)/n)*P[n-2](x)
  7.  
  8. (define (legendre-polynomials)
  9.   (define s
  10.     (cons-stream
  11.       '(1)
  12.       (cons-stream 
  13.         '(0 1)
  14.         (map-streams (lambda (p1 p2)
  15.                        (let* ((n (length p1))
  16.                               (a (/ (- (* 2 n) 1) n))
  17.                               (b (/ (- n 1) n)))
  18.                          (sub-polys (mul-polys (list 0 a) p1)
  19.                                     (scale-poly b p2))))
  20.                      (tail s)
  21.                      s))))
  22.   s)
  23.           
  24.  
  25. (define (legendre-poly n)
  26.   (let ((s (legendre-polynomials)))
  27.     (stream-ref s n)))
  28.